package com.zlsoft.web.config;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.view.WindowManager;

/**
 * @author - qqz
 * @date - 2021-12-16/10:54
 * @note -
 * ---------------------------------------------------------------------------------------------------------------------------------
 * @modified -
 * @date -
 * @note -
 */
public class WebViewBaseConfig {

    private static WebViewBaseConfig sMWebViewBaseConfig;

    public static WebViewBaseConfig getBaseConfig() {

        synchronized (WebViewBaseConfig.class) {
            if (null == sMWebViewBaseConfig) {
                sMWebViewBaseConfig = new WebViewBaseConfig();
            }
        }

        return sMWebViewBaseConfig;
    }

    /**
     * 通用处理Url
     *
     * @param url  url
     * @return 参见处理结果(PROCESS_NOTHING等)
     */
    public int processShouldOverrideUrlLoading(Activity mActivity, String url) {
        if (!url.startsWith("http") && !url.startsWith("https") && !url.startsWith("yy")) {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mActivity. startActivity(intent);
                return 1;

            } catch (Exception ignored) {
            }
        }

        return 0;
    }
    /**
     * 启用硬件加速
     */
    public void initHardwareAccelerate(Activity mActivity) {
        try {
            if (Integer.parseInt(Build.VERSION.SDK) >= 11) {
                mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
            }
        } catch (Exception ignored) {
        }
    }

}
